import Mock from "mockjs";

let template = (option) => {
  console.log(option, "image.pngimage.png");
  let a = { ...option };
  if (option == null) {
    a.size = 10;
    a.current = 1;
  }
  // let size =  a.size ? a.size : '10'
  // let current = a.current ?a.current : '1'
  return {
    code: "000000",
    mesg: "success",
    data: {
      total: 10,
      size: a.size,
      current: a.current,
      [`records|${a.size}`]: [
        {
          "id|+1": 1,
          // mock单位名称怎么写？
          companyCode: "@integer(100, 1000)",
          companyName: "@cname",
          regulationOrgCode: "@integer(100, 1000)",
          regulationOrgName: "@cname",
          singleMachineCap: "@integer(100, 1000)",
          stationCode: "@integer(100, 1000)",
          stationName: "@cname",
          stationType: "@integer(100, 1000)",
          stationTypeName: "@cname",
          unitsName: "@cname",
          unitsNumber: "@integer(100, 1000)",
          planningName: "@integer(100, 1000)",

          // @province()
          // unitCode: "@county(true)",
          // validTime: `@date()~@date()`,
          // buyTime: `@date()~@date()`,

          // "age|18-60": 1,
          // "gender|1": ["男", "女"],
          // email: "@email",
          // phone: /^1[34578]\d{9}$/,
          // avatar: '@image("200x200", "#50B347", "#FFF", "Mock.js")',
        },
      ],
    },
  };
};

//表示需要拦截的 URL，可以是 URL 字符串或 URL 正则。
//表示需要拦截的 Ajax 请求类型。例如 GET、POST、PUT、DELETE 等。
//表示数据模板，可以是对象或字符串。例如 { 'data|1-10':[{}] }、'@EMAIL'。
Mock.mock("/test/table/list", "post", (options) => {
  let option = JSON.parse(options.body);
  // console.log(JSON.parse(options.body))
  return Mock.mock(template(option));
});
